import { defineStore } from "pinia";
import type { useHomeState } from "../interface/index";
import {
  reqSaleRankList,
  reqBanners,
  reqrecommendList,
  reqFloors,
} from "@/api/home/index";
export const useHomeStore = defineStore("home", {
  state(): useHomeState {
    return {
      saleRankList: {
        name: "",
        imgUrl: "",
        subSaleRankList: [],
      },
      banners: [],
      recommendList: [],
      floors: [],
    };
  },
  actions: {
    //获取首页百强榜数据
    async getSaleRankList() {
      this.saleRankList = await reqSaleRankList();
    },
    // 获取首页轮播图数据
    async getBanners() {
      this.banners = await reqBanners();
    },
    // 获取推荐楼层数据
    async getRecommendList() {
      this.recommendList = await reqrecommendList();
    },
    // 获取分类楼层数据
    async getFloors() {
      this.floors = await reqFloors();
    },
  },
  getters: {
    recommend(state) {
      return state.recommendList[0];
    },
    hot(state) {
      return state.recommendList[1];
    },
  },
});
